

create view [dbo].[uv_SaleItem]
as
select  wh.WhsName, gr.ItmsGrpNam, it.U_MinorGroup, mi.Name MinorGroupName, it.ItemCode, it.ItemName,
			sum(iv.Quantity) Quantity, sum(iv.PriceBefDi*iv.Quantity) Subtotal, 
			sum(iv.PriceBefDi*iv.Quantity-iv.LineTotal) DiscAmt,sum(iv.LineTotal) TotalAfterDiscount,
			sum(iv.VatSum) VAT ,sum(iv2.LineTotal) ServiceCharge, sum(iv.GTotal+iv2.LineTotal) Nettotal,
			
			iv.DocDate, wh.WhsCode, gr.ItmsGrpCod
	from INV1 iv 
	left join INV2 iv2 on iv2.DocEntry=iv.DocEntry and iv2.LineNum=iv.LineNum
	join OWHS wh on iv.WhsCode = wh.WhsCode 
	join OITM it on iv.ItemCode = it.ItemCode
	join OITB gr on it.ItmsGrpCod = gr.ItmsGrpCod
	left join [@MINORGROUP] mi on  it.U_MinorGroup = mi.Code		
	group by wh.WhsName, gr.ItmsGrpNam, it.U_MinorGroup, it.ItemCode, it.ItemName, 
	mi.Name, iv.DocDate, wh.WhsCode, gr.ItmsGrpCod 		

--select * from uv_SaleItem
GO


--select * from INV1